

import javax.sql.DataSource;

import com.dc.free.util.DruidPluginUtil;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.generator.Generator;
import com.jfinal.plugin.druid.DruidPlugin;

/**
 * GeneratorDemo
 */
public class IModelGenerator {
	
	public static DataSource getDataSource() {
		DruidPlugin druidPlugin = DruidPluginUtil.create();
		druidPlugin.start();
		return druidPlugin.getDataSource();
	}
	
	public static void main(String[] args) {
		// base model 所使用的包名
		String baseModelPackageName = "com.dc.free.db.bean";
		// base model 文件保存路径
		String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/dc/free/db/bean";
		
		// model 所使用的包名 (MappingKit 默认使用的包名)
		String modelPackageName = "com.dc.free.db.model";
		// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
		String modelOutputDir = baseModelOutputDir + "/../model";
		
		// 创建生成器
		Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
		// 设置数据库方言
		gernerator.setDialect(DruidPluginUtil.getDialect());
		// 添加不需要生成的表名
		//gernerator.addExcludedTable("s_application","s_corpapp","s_corporation","s_department","s_feedback","s_group","s_groupadmin","s_groupapps","s_groupdept","s_hooks","s_hooksdata","s_hooksevent","s_interface","s_log","s_loginlog","s_parameter","s_privilege","s_privilegerole","s_privilegeuser","s_role","s_roledepartment","s_roleuser","s_soa","s_staticresource","s_subinterface","s_synclog","s_user","s_userextdescription");
		// 设置是否在 Model 中生成 dao 对象
		gernerator.setGenerateDaoInModel(true);
		// 设置是否生成字典文件
		gernerator.setGenerateDataDictionary(true);
		// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user"，移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
		gernerator.setRemovedTableNamePrefixes("s_");
		// 生成
		gernerator.generate();
	}
}




